<!--
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
-->
<!--
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
-->
<!--
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
-->
<template>
  <el-form
    :model="ruleForm"
    :rules="rules"
    ref="ruleForm"
    label-width="100px"
    class="demo-ruleForm"
  >
    <el-form-item label="公司名称" prop="name">
      <el-input v-model="ruleForm.name"></el-input>
    </el-form-item>
    <el-form-item label="企业法人" prop="boss">
      <el-input v-model="ruleForm.boss"></el-input>
    </el-form-item>
    <el-form-item label="注册资本" prop="regCapital">
      <el-input v-model="ruleForm.regCapital"></el-input>
    </el-form-item>
    <el-form-item label="所属行业" prop="industry">
      <el-input v-model="ruleForm.industry"></el-input>
    </el-form-item>
    <el-row :gutter="20">
      <el-col :span="12" :offset="0">
        <el-form-item label="企业LOGO" prop="logo">
          <img-upload v-model:changeImg="ruleForm.logo" />
        </el-form-item>
      </el-col>
      <el-col :span="12" :offset="0">
        <el-form-item label="营业执照" prop="license">
          <img-upload v-model:changeImg="ruleForm.license" />
        </el-form-item>
      </el-col>
    </el-row>

    <el-form-item label="地图选址" prop="address">
      <el-row style="width: 100%">
        <el-col :span="20" :offset="0">
          <el-input v-model="ruleForm.address" readonly></el-input>
        </el-col>
        <el-col :span="4" :offset="0">
          <el-button type="primary" size="default" @click="drawer = true"
            >点击选址</el-button
          >
        </el-col>
      </el-row>
      <el-drawer v-model="drawer" title="地图选址" direction="btt" size="60%">
        <GdMap @pass-address="handleAddress" />
      </el-drawer>
    </el-form-item>
    <el-form-item label="公司简介" prop="intro">
      <div class="editor">
        <QuillEditor v-model:content="ruleForm.intro" contentType="html" />
      </div>
    </el-form-item>
    <el-form-item label="是否上架" prop="online">
      <el-switch v-model="ruleForm.online"></el-switch>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')"
        >立即创建</el-button
      >
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import { companyPost } from "@/api/job";
import { QuillEditor } from "@vueup/vue-quill";
import "@vueup/vue-quill/dist/vue-quill.snow.css";
import GdMap from "@/components/gd-map.vue";
export default {
  components: {
    QuillEditor,
    GdMap,
  },
  data() {
    return {
      drawer: true, //控制抽屉显示
      ruleForm: {
        name: "万锋互联",
        boss: "卢老师",
        regCapital: "20000万",
        industry: "网络会所",
        logo: "",
        license: "",
        address: "1",
        intro: "2",
        online: true,
      },
      rules: {
        name: [{ required: true, message: "请输入分类名称", trigger: "blur" }],
        boss: [{ required: true, message: "请录入法人信息", trigger: "blur" }],
        regCapital: [
          { required: true, message: "请录入注册资本", trigger: "blur" },
        ],
        industry: [{ required: true, message: "请输入行业", trigger: "blur" }],
        logo: [{ required: true, message: "请上传LOGO", trigger: "blur" }],
        license: [
          { required: true, message: "请上传营业执照", trigger: "blur" },
        ],
        location: [
          { required: true, message: "请选择公司位置", trigger: "blur" },
        ],
        intro: [{ required: true, message: "请输入公司简介", trigger: "blur" }],
      },
      cfyList: [], //分类列表
    };
  },

  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //如何获取表单数据
          console.log(this.ruleForm);
          companyPost(this.ruleForm);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    //接收地图组件传递的地理位置信息
    handleAddress(location) {
      console.log("父组件接收的数据", location);
      this.ruleForm = {
        ...this.ruleForm,
        ...location,
      };
    },
  },
};
</script>
<style scoped>
.editor {
  width: 100%;
}
.editor :deep(.ql-toolbar) {
  width: 100%;
}
.editor :deep(.ql-container) {
  width: 100%;
  height: 300px;
}
</style>
